@terrafirmagreg-team/kit 0.0.0-stage → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +68 -3
- package/src/components/blocks/nav-title.tsx +65 -0
- package/src/components/docs-image.tsx +49 -0
- package/src/components/outline/dropdown.tsx +67 -0
- package/src/components/outline/index.ts +10 -0
- package/src/components/outline/list.tsx +120 -0
- package/src/components/outline/outline.tsx +49 -0
- package/src/components/outline/popover.tsx +76 -0
- package/src/components/outline/types.ts +29 -0
- package/src/components/page-actions.tsx +201 -0
- package/src/components/relative-link.tsx +18 -0
- package/src/components/search/dialog.tsx +145 -0
- package/src/components/toc/base.tsx +65 -0
- package/src/components/toc/block.tsx +111 -0
- package/src/components/toc/clerk.tsx +265 -0
- package/src/components/toc/default.tsx +333 -0
- package/src/components/version-menu.tsx +128 -0
- package/src/components/views/dataset.tsx +63 -0
- package/src/components/views/section.tsx +108 -0
- package/src/components/workspace/content.tsx +53 -0
- package/src/components/workspace/index.ts +12 -0
- package/src/components/workspace/pagination.tsx +73 -0
- package/src/components/workspace/workspace.tsx +148 -0
- package/src/hooks/toc.ts +9 -0
- package/src/hooks/use-catalog.ts +11 -0
- package/src/hooks/use-current-dataset.ts +14 -0
- package/src/hooks/use-dataset-accent.ts +13 -0
- package/src/hooks/use-nav-options.ts +84 -0
- package/src/hooks/use-version-pref.ts +30 -0
- package/src/lib/breadcrumb.ts +78 -0
- package/src/lib/config.ts +109 -0
- package/src/lib/dataset-links.ts +30 -0
- package/src/lib/datasets.ts +211 -0
- package/src/lib/landing.ts +46 -0
- package/src/lib/layout.ts +15 -0
- package/src/lib/legacy.ts +18 -0
- package/src/lib/location.ts +63 -0
- package/src/lib/markdown/dom.ts +90 -0
- package/src/lib/markdown/index.ts +13 -0
- package/src/lib/markdown/providers.ts +25 -0
- package/src/lib/mdx/accordions.ts +93 -0
- package/src/lib/mdx/banner.ts +52 -0
- package/src/lib/mdx/directive-utils.ts +125 -0
- package/src/lib/mdx/directives.ts +141 -0
- package/src/lib/mdx/game-export.ts +44 -0
- package/src/lib/mdx/html-style.ts +135 -0
- package/src/lib/mdx/preview.ts +252 -0
- package/src/lib/mdx/references.ts +56 -0
- package/src/lib/mdx/tabs.ts +80 -0
- package/src/lib/mdx-components.tsx +139 -0
- package/src/lib/order.ts +88 -0
- package/src/lib/pack-assets.ts +45 -0
- package/src/lib/page.ts +108 -0
- package/src/lib/pin-tree.ts +35 -0
- package/src/lib/preview/index.ts +8 -0
- package/src/lib/preview/lookup.ts +48 -0
- package/src/lib/preview/og.tsx +115 -0
- package/src/lib/preview/resolvers.ts +98 -0
- package/src/lib/search/config.ts +13 -0
- package/src/lib/search/filters.ts +22 -0
- package/src/lib/search/index.ts +19 -0
- package/src/lib/search/indexes.ts +43 -0
- package/src/lib/search/merge.ts +22 -0
- package/src/lib/search/server.ts +18 -0
- package/src/lib/search/sources.ts +19 -0
- package/src/lib/search/structured.ts +23 -0
- package/src/lib/section/schema.ts +36 -0
- package/src/lib/section/source.ts +40 -0
- package/src/lib/sources.ts +21 -0
- package/src/lib/tree.ts +60 -0
- package/src/lib/urls.ts +16 -0
- package/src/locales/en_us.json +10 -0
- package/src/locales/ru_ru.json +10 -0
- package/src/locales.ts +5 -0
- package/src/types/index.ts +83 -0
- package/src/types/mdx.ts +55 -0
- package/src/types/turndown-plugin-gfm.d.ts +9 -0
- package/README.md +0 -3
package/package.json
CHANGED
|
@@ -1,6 +1,71 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@terrafirmagreg-team/kit",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"exports": {
|
|
6
|
+
"./lib/*": [
|
|
7
|
+
"./src/lib/*.ts",
|
|
8
|
+
"./src/lib/*.tsx",
|
|
9
|
+
"./src/lib/*/index.ts",
|
|
10
|
+
"./src/lib/*/index.tsx"
|
|
11
|
+
],
|
|
12
|
+
"./types/*": "./src/types/*.ts",
|
|
13
|
+
"./hooks/*": [
|
|
14
|
+
"./src/hooks/*.ts",
|
|
15
|
+
"./src/hooks/*.tsx",
|
|
16
|
+
"./src/hooks/*/index.ts",
|
|
17
|
+
"./src/hooks/*/index.tsx"
|
|
18
|
+
],
|
|
19
|
+
"./types": "./src/types/index.ts",
|
|
20
|
+
"./components/*": [
|
|
21
|
+
"./src/components/*.ts",
|
|
22
|
+
"./src/components/*.tsx",
|
|
23
|
+
"./src/components/*/index.ts",
|
|
24
|
+
"./src/components/*/index.tsx"
|
|
25
|
+
],
|
|
26
|
+
"./locales": "./src/locales.ts"
|
|
27
|
+
},
|
|
28
|
+
"dependencies": {
|
|
29
|
+
"@base-ui/react": "^1.9.0",
|
|
30
|
+
"@icons-pack/react-simple-icons": "13.15.1",
|
|
31
|
+
"@terrafirmagreg-team/translate": "0.1.0",
|
|
32
|
+
"@terrafirmagreg-team/ui": "0.1.0",
|
|
33
|
+
"fumadocs-core": "16.17.8",
|
|
34
|
+
"fumadocs-mdx": "15.4.10",
|
|
35
|
+
"fumadocs-twoslash": "^4.0.4",
|
|
36
|
+
"lucide-react": "^1.63.0",
|
|
37
|
+
"remark-directive": "^4.0.0",
|
|
38
|
+
"remark-gfm": "^4.0.1",
|
|
39
|
+
"remark-math": "^6.0.0",
|
|
40
|
+
"remark-parse": "^11.0.0",
|
|
41
|
+
"server-only": "^0.0.1",
|
|
42
|
+
"turndown": "^7.2.4",
|
|
43
|
+
"turndown-plugin-gfm": "^1.0.2",
|
|
44
|
+
"unified": "^11.0.5",
|
|
45
|
+
"zod": "4.6.7"
|
|
46
|
+
},
|
|
47
|
+
"peerDependencies": {
|
|
48
|
+
"next": ">=15",
|
|
49
|
+
"react": ">=19"
|
|
50
|
+
},
|
|
51
|
+
"devDependencies": {
|
|
52
|
+
"@types/mdx": "^2.0.14",
|
|
53
|
+
"@types/node": "^26.6.5",
|
|
54
|
+
"@types/react": "^19.3.0",
|
|
55
|
+
"@types/react-dom": "^19.3.0",
|
|
56
|
+
"@types/turndown": "^5.0.6"
|
|
57
|
+
},
|
|
58
|
+
"repository": {
|
|
59
|
+
"type": "git",
|
|
60
|
+
"url": "https://github.com/TerraFirmaGreg-Team/Web-Foundation.git",
|
|
61
|
+
"directory": "packages/kit"
|
|
62
|
+
},
|
|
63
|
+
"publishConfig": {
|
|
64
|
+
"access": "public"
|
|
65
|
+
},
|
|
66
|
+
"files": [
|
|
67
|
+
"src",
|
|
68
|
+
"styles",
|
|
69
|
+
"styles.css"
|
|
70
|
+
]
|
|
6
71
|
}
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
|
|
3
|
+
import { usePathname } from 'next/navigation';
|
|
4
|
+
import type { ComponentProps } from 'react';
|
|
5
|
+
|
|
6
|
+
import { uiConfig } from '@terrafirmagreg-team/ui/lib/config';
|
|
7
|
+
import { SiteTitle } from '@terrafirmagreg-team/ui/components/blocks/nav/site-title';
|
|
8
|
+
import { useAsyncValue } from '@terrafirmagreg-team/ui/hooks/use-async-value';
|
|
9
|
+
import { clientDumpLoader } from '@terrafirmagreg-team/kit/lib/config';
|
|
10
|
+
import {
|
|
11
|
+
datasetRef,
|
|
12
|
+
isDumpSection,
|
|
13
|
+
parseDatasetRef,
|
|
14
|
+
parseSectionLocation,
|
|
15
|
+
} from '@terrafirmagreg-team/kit/lib/location';
|
|
16
|
+
import {
|
|
17
|
+
setVersionPreference,
|
|
18
|
+
useVersionPreference,
|
|
19
|
+
} from '@terrafirmagreg-team/kit/hooks/use-version-pref';
|
|
20
|
+
import { VersionMenu } from '@terrafirmagreg-team/kit/components/version-menu';
|
|
21
|
+
|
|
22
|
+
export function NavTitle({ className, ...props }: ComponentProps<'a'>) {
|
|
23
|
+
const { section, dataset } = parseSectionLocation(usePathname());
|
|
24
|
+
const datasetId = dataset ? parseDatasetRef(dataset).id : undefined;
|
|
25
|
+
const gameData = isDumpSection(section);
|
|
26
|
+
const pref = useVersionPreference(datasetId);
|
|
27
|
+
const version = useAsyncValue(
|
|
28
|
+
dataset
|
|
29
|
+
? () =>
|
|
30
|
+
clientDumpLoader()
|
|
31
|
+
.loadDump(dataset)
|
|
32
|
+
.then((dump) => dump?.manifest.pack?.version ?? undefined)
|
|
33
|
+
: false,
|
|
34
|
+
[dataset],
|
|
35
|
+
);
|
|
36
|
+
const versions = useAsyncValue(
|
|
37
|
+
datasetId ? () => clientDumpLoader().loadVersions(datasetId) : false,
|
|
38
|
+
[datasetId],
|
|
39
|
+
);
|
|
40
|
+
return (
|
|
41
|
+
<SiteTitle
|
|
42
|
+
href="/"
|
|
43
|
+
icon={uiConfig().brand?.icon ?? ''}
|
|
44
|
+
name={uiConfig().brand?.name ?? ''}
|
|
45
|
+
subtitle={
|
|
46
|
+
dataset && datasetId ? (
|
|
47
|
+
<VersionMenu
|
|
48
|
+
section={section}
|
|
49
|
+
datasetId={datasetId}
|
|
50
|
+
currentRef={gameData ? dataset : datasetRef(datasetId, pref)}
|
|
51
|
+
label={gameData ? version : (pref ?? version)}
|
|
52
|
+
versions={versions}
|
|
53
|
+
onSelect={
|
|
54
|
+
gameData || !datasetId
|
|
55
|
+
? undefined
|
|
56
|
+
: (next) => setVersionPreference(datasetId, next)
|
|
57
|
+
}
|
|
58
|
+
/>
|
|
59
|
+
) : undefined
|
|
60
|
+
}
|
|
61
|
+
className={className}
|
|
62
|
+
{...props}
|
|
63
|
+
/>
|
|
64
|
+
);
|
|
65
|
+
}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { ImageZoom } from '@terrafirmagreg-team/ui/components/mdx/image-zoom';
|
|
2
|
+
import { resolveSrc } from '@terrafirmagreg-team/kit/lib/pack-assets';
|
|
3
|
+
import type { DocsImageProps } from '@terrafirmagreg-team/kit/types/mdx';
|
|
4
|
+
|
|
5
|
+
export function DocsImage({
|
|
6
|
+
src,
|
|
7
|
+
pack,
|
|
8
|
+
mod,
|
|
9
|
+
path,
|
|
10
|
+
alt = '',
|
|
11
|
+
width,
|
|
12
|
+
height,
|
|
13
|
+
className,
|
|
14
|
+
caption,
|
|
15
|
+
defaultPack: pagePack,
|
|
16
|
+
...rest
|
|
17
|
+
}: DocsImageProps) {
|
|
18
|
+
const packHint = pack ?? pagePack;
|
|
19
|
+
const resolved = resolveSrc({ src, pack, mod, path }, packHint);
|
|
20
|
+
if (!resolved) {
|
|
21
|
+
return (
|
|
22
|
+
<p className="not-prose text-sm text-muted-foreground">
|
|
23
|
+
Missing image source (set <code>src</code> or <code>mod</code>+
|
|
24
|
+
<code>path</code>; pack defaults from the docs slug).
|
|
25
|
+
</p>
|
|
26
|
+
);
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
const w = Number(width) || 960;
|
|
30
|
+
const h = Number(height) || 540;
|
|
31
|
+
|
|
32
|
+
return (
|
|
33
|
+
<figure className="not-prose my-4 space-y-2">
|
|
34
|
+
<ImageZoom
|
|
35
|
+
src={resolved}
|
|
36
|
+
alt={alt}
|
|
37
|
+
width={w}
|
|
38
|
+
height={h}
|
|
39
|
+
className={className}
|
|
40
|
+
{...rest}
|
|
41
|
+
/>
|
|
42
|
+
{caption ? (
|
|
43
|
+
<figcaption className="text-center text-sm text-muted-foreground">
|
|
44
|
+
{caption}
|
|
45
|
+
</figcaption>
|
|
46
|
+
) : null}
|
|
47
|
+
</figure>
|
|
48
|
+
);
|
|
49
|
+
}
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
import { Popover } from '@base-ui/react/popover';
|
|
3
|
+
import { cn } from '@terrafirmagreg-team/ui/lib/utils/cn';
|
|
4
|
+
import { useTranslations } from '@terrafirmagreg-team/translate/hooks/use-translations';
|
|
5
|
+
import { ChevronDownIcon } from 'lucide-react';
|
|
6
|
+
import { useState } from 'react';
|
|
7
|
+
import { OutlineActiveHeading, OutlineList, OutlineProgress } from './list';
|
|
8
|
+
import type { WorkspaceOutlineDropdownProps } from './types';
|
|
9
|
+
|
|
10
|
+
export function WorkspaceOutlineDropdown({
|
|
11
|
+
trigger,
|
|
12
|
+
content,
|
|
13
|
+
header,
|
|
14
|
+
footer,
|
|
15
|
+
...props
|
|
16
|
+
}: WorkspaceOutlineDropdownProps) {
|
|
17
|
+
const t = useTranslations();
|
|
18
|
+
const [open, setOpen] = useState(false);
|
|
19
|
+
|
|
20
|
+
return (
|
|
21
|
+
<Popover.Root open={open} onOpenChange={setOpen}>
|
|
22
|
+
<Popover.Trigger
|
|
23
|
+
{...trigger}
|
|
24
|
+
className={cn(
|
|
25
|
+
'flex items-center gap-2 min-w-0 h-8 px-1.5 -mx-1.5 rounded-lg text-start text-sm transition-colors',
|
|
26
|
+
open
|
|
27
|
+
? 'bg-accent text-accent-foreground'
|
|
28
|
+
: 'text-muted-foreground hover:bg-accent/60 hover:text-accent-foreground',
|
|
29
|
+
trigger?.className,
|
|
30
|
+
)}
|
|
31
|
+
>
|
|
32
|
+
<OutlineProgress className="shrink-0" />
|
|
33
|
+
<OutlineActiveHeading
|
|
34
|
+
fallback={t('ui.on_this_page')}
|
|
35
|
+
activeClassName="text-foreground"
|
|
36
|
+
/>
|
|
37
|
+
<ChevronDownIcon
|
|
38
|
+
className={cn('size-3.5 shrink-0 transition-transform', open && 'rotate-180')}
|
|
39
|
+
/>
|
|
40
|
+
</Popover.Trigger>
|
|
41
|
+
<Popover.Portal>
|
|
42
|
+
<Popover.Positioner
|
|
43
|
+
align="start"
|
|
44
|
+
sideOffset={8}
|
|
45
|
+
positionMethod="fixed"
|
|
46
|
+
className="z-50"
|
|
47
|
+
>
|
|
48
|
+
<Popover.Popup
|
|
49
|
+
{...content}
|
|
50
|
+
className={cn(
|
|
51
|
+
'flex flex-col w-88 max-w-(--available-width) max-h-[min(28rem,var(--available-height))] p-3 rounded-2xl border bg-popover text-popover-foreground shadow-xl outline-none origin-(--transform-origin) transition-[opacity,scale] duration-150 ease-[cubic-bezier(0.22,1,0.36,1)] data-starting-style:opacity-0 data-starting-style:scale-95 data-ending-style:opacity-0 data-ending-style:scale-95 motion-reduce:transition-none',
|
|
52
|
+
content?.className,
|
|
53
|
+
)}
|
|
54
|
+
>
|
|
55
|
+
{header}
|
|
56
|
+
<OutlineList
|
|
57
|
+
{...props}
|
|
58
|
+
className="py-1"
|
|
59
|
+
onSelect={() => setOpen(false)}
|
|
60
|
+
/>
|
|
61
|
+
{footer}
|
|
62
|
+
</Popover.Popup>
|
|
63
|
+
</Popover.Positioner>
|
|
64
|
+
</Popover.Portal>
|
|
65
|
+
</Popover.Root>
|
|
66
|
+
);
|
|
67
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export type {
|
|
2
|
+
OutlineStyle,
|
|
3
|
+
OutlineContent,
|
|
4
|
+
OutlineProps,
|
|
5
|
+
WorkspaceOutlineDropdownProps,
|
|
6
|
+
WorkspaceOutlinePopoverProps,
|
|
7
|
+
} from './types';
|
|
8
|
+
export { Outline, RightSidebarOutline } from './outline';
|
|
9
|
+
export { WorkspaceOutlinePopover } from './popover';
|
|
10
|
+
export { WorkspaceOutlineDropdown } from './dropdown';
|
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
import { type TOCItemInfo, useTOCSelector } from '@terrafirmagreg-team/kit/components/toc/base';
|
|
3
|
+
import { useTOCItems } from '@terrafirmagreg-team/kit/hooks/toc';
|
|
4
|
+
import * as Base from '@terrafirmagreg-team/kit/components/toc/base';
|
|
5
|
+
import * as OutlineDefault from '@terrafirmagreg-team/kit/components/toc/default';
|
|
6
|
+
import * as OutlineClerk from '@terrafirmagreg-team/kit/components/toc/clerk';
|
|
7
|
+
import * as OutlineBlock from '@terrafirmagreg-team/kit/components/toc/block';
|
|
8
|
+
import { cn } from '@terrafirmagreg-team/ui/lib/utils/cn';
|
|
9
|
+
import {
|
|
10
|
+
type ComponentProps,
|
|
11
|
+
type CSSProperties,
|
|
12
|
+
type ReactNode,
|
|
13
|
+
useState,
|
|
14
|
+
} from 'react';
|
|
15
|
+
import type { OutlineStyle } from './types';
|
|
16
|
+
|
|
17
|
+
const variants = {
|
|
18
|
+
normal: OutlineDefault,
|
|
19
|
+
clerk: OutlineClerk,
|
|
20
|
+
block: OutlineBlock,
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
const selectTopmost = (items: TOCItemInfo[]) =>
|
|
24
|
+
items.find((item) => item.active)?.original;
|
|
25
|
+
const selectProgress = (items: TOCItemInfo[]) =>
|
|
26
|
+
(items.findLastIndex((item) => item.active) + 1) / Math.max(1, items.length);
|
|
27
|
+
|
|
28
|
+
export function OutlineList({
|
|
29
|
+
style = 'block',
|
|
30
|
+
list,
|
|
31
|
+
className,
|
|
32
|
+
onSelect,
|
|
33
|
+
}: OutlineStyle & { className?: string; onSelect?: () => void }) {
|
|
34
|
+
const items = useTOCItems();
|
|
35
|
+
const { TOCItems, TOCItem, TOCEmpty } = variants[style];
|
|
36
|
+
|
|
37
|
+
return (
|
|
38
|
+
<Base.TOCScrollArea className={className}>
|
|
39
|
+
<TOCItems {...list}>
|
|
40
|
+
{items.length === 0 && <TOCEmpty />}
|
|
41
|
+
{items.map((item) => (
|
|
42
|
+
<TOCItem key={item.url} item={item} onClick={onSelect} />
|
|
43
|
+
))}
|
|
44
|
+
</TOCItems>
|
|
45
|
+
</Base.TOCScrollArea>
|
|
46
|
+
);
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
export function OutlineActiveHeading({
|
|
50
|
+
fallback,
|
|
51
|
+
className,
|
|
52
|
+
activeClassName,
|
|
53
|
+
}: {
|
|
54
|
+
fallback: ReactNode;
|
|
55
|
+
className?: string;
|
|
56
|
+
activeClassName?: string;
|
|
57
|
+
}) {
|
|
58
|
+
const items = useTOCItems();
|
|
59
|
+
const active = useTOCSelector(selectTopmost);
|
|
60
|
+
const [shown, setShown] = useState({ item: active, roll: 1 });
|
|
61
|
+
if (shown.item !== active) {
|
|
62
|
+
setShown({
|
|
63
|
+
item: active,
|
|
64
|
+
roll: items.indexOf(active!) >= items.indexOf(shown.item!) ? 1 : -1,
|
|
65
|
+
});
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
return (
|
|
69
|
+
<span
|
|
70
|
+
className={cn('flex min-w-0 overflow-hidden', active && activeClassName, className)}
|
|
71
|
+
>
|
|
72
|
+
<span
|
|
73
|
+
key={active?.url}
|
|
74
|
+
className="truncate motion-safe:animate-roll-in"
|
|
75
|
+
style={{ '--roll': shown.roll } as CSSProperties}
|
|
76
|
+
>
|
|
77
|
+
{active ? active.title : fallback}
|
|
78
|
+
</span>
|
|
79
|
+
</span>
|
|
80
|
+
);
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
export function OutlineProgress({
|
|
84
|
+
size = 16,
|
|
85
|
+
...props
|
|
86
|
+
}: ComponentProps<'svg'> & { size?: number }) {
|
|
87
|
+
const value = useTOCSelector(selectProgress);
|
|
88
|
+
const circle = {
|
|
89
|
+
cx: size / 2,
|
|
90
|
+
cy: size / 2,
|
|
91
|
+
r: size / 2 - 1.5,
|
|
92
|
+
fill: 'none',
|
|
93
|
+
strokeWidth: 1.5,
|
|
94
|
+
};
|
|
95
|
+
const circumference = 2 * Math.PI * circle.r;
|
|
96
|
+
|
|
97
|
+
return (
|
|
98
|
+
<svg
|
|
99
|
+
role="progressbar"
|
|
100
|
+
viewBox={`0 0 ${size} ${size}`}
|
|
101
|
+
width={size}
|
|
102
|
+
height={size}
|
|
103
|
+
aria-valuenow={value}
|
|
104
|
+
aria-valuemin={0}
|
|
105
|
+
aria-valuemax={1}
|
|
106
|
+
{...props}
|
|
107
|
+
>
|
|
108
|
+
<circle {...circle} className="stroke-current/25" />
|
|
109
|
+
<circle
|
|
110
|
+
{...circle}
|
|
111
|
+
stroke="currentColor"
|
|
112
|
+
strokeLinecap="round"
|
|
113
|
+
strokeDasharray={circumference}
|
|
114
|
+
strokeDashoffset={circumference * (1 - value)}
|
|
115
|
+
transform={`rotate(-90 ${circle.cx} ${circle.cy})`}
|
|
116
|
+
className="transition-[stroke-dashoffset] duration-300"
|
|
117
|
+
/>
|
|
118
|
+
</svg>
|
|
119
|
+
);
|
|
120
|
+
}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
import { useTOCItems } from '@terrafirmagreg-team/kit/hooks/toc';
|
|
3
|
+
import { cn } from '@terrafirmagreg-team/ui/lib/utils/cn';
|
|
4
|
+
import { useTranslations } from '@terrafirmagreg-team/translate/hooks/use-translations';
|
|
5
|
+
import { TextIcon } from 'lucide-react';
|
|
6
|
+
import {
|
|
7
|
+
RightSidebarPanel,
|
|
8
|
+
RightSidebarPortal,
|
|
9
|
+
} from '@terrafirmagreg-team/ui/components/layouts/right-sidebar';
|
|
10
|
+
import { OutlineList } from './list';
|
|
11
|
+
import type { OutlineProps } from './types';
|
|
12
|
+
|
|
13
|
+
export function Outline({ container, header, footer, ...props }: OutlineProps) {
|
|
14
|
+
const t = useTranslations();
|
|
15
|
+
const items = useTOCItems();
|
|
16
|
+
if (items.length === 0 && !header && !footer) return;
|
|
17
|
+
|
|
18
|
+
return (
|
|
19
|
+
<div
|
|
20
|
+
data-slot="outline"
|
|
21
|
+
{...container}
|
|
22
|
+
className={cn('flex min-h-0 flex-col overflow-clip', container?.className)}
|
|
23
|
+
>
|
|
24
|
+
{header}
|
|
25
|
+
<h3 className="inline-flex items-center gap-1.5 text-sm text-muted-foreground">
|
|
26
|
+
<TextIcon className="size-4" />
|
|
27
|
+
{t('ui.on_this_page')}
|
|
28
|
+
</h3>
|
|
29
|
+
<OutlineList {...props} />
|
|
30
|
+
{footer}
|
|
31
|
+
</div>
|
|
32
|
+
);
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export function RightSidebarOutline({ container, ...props }: OutlineProps) {
|
|
36
|
+
return (
|
|
37
|
+
<RightSidebarPortal>
|
|
38
|
+
<RightSidebarPanel className="pt-8 pb-4">
|
|
39
|
+
<Outline
|
|
40
|
+
{...props}
|
|
41
|
+
container={{
|
|
42
|
+
...container,
|
|
43
|
+
className: cn('flex-1', container?.className),
|
|
44
|
+
}}
|
|
45
|
+
/>
|
|
46
|
+
</RightSidebarPanel>
|
|
47
|
+
</RightSidebarPortal>
|
|
48
|
+
);
|
|
49
|
+
}
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
import {
|
|
3
|
+
Collapsible,
|
|
4
|
+
CollapsibleContent,
|
|
5
|
+
CollapsibleTrigger,
|
|
6
|
+
} from '@terrafirmagreg-team/ui/components/ui/collapsible';
|
|
7
|
+
import { cn } from '@terrafirmagreg-team/ui/lib/utils/cn';
|
|
8
|
+
import { useTranslations } from '@terrafirmagreg-team/translate/hooks/use-translations';
|
|
9
|
+
import { ChevronDownIcon } from 'lucide-react';
|
|
10
|
+
import { useEffect, useRef, useState } from 'react';
|
|
11
|
+
import { useTreePath } from '@terrafirmagreg-team/ui/hooks/use-tree';
|
|
12
|
+
import { OutlineActiveHeading, OutlineList, OutlineProgress } from './list';
|
|
13
|
+
import type { WorkspaceOutlinePopoverProps } from './types';
|
|
14
|
+
|
|
15
|
+
export function WorkspaceOutlinePopover({
|
|
16
|
+
container,
|
|
17
|
+
trigger,
|
|
18
|
+
content,
|
|
19
|
+
header,
|
|
20
|
+
footer,
|
|
21
|
+
...props
|
|
22
|
+
}: WorkspaceOutlinePopoverProps) {
|
|
23
|
+
const t = useTranslations();
|
|
24
|
+
const page = useTreePath().at(-1);
|
|
25
|
+
const ref = useRef<HTMLElement>(null);
|
|
26
|
+
const [open, setOpen] = useState(false);
|
|
27
|
+
|
|
28
|
+
useEffect(() => {
|
|
29
|
+
if (!open) return;
|
|
30
|
+
const onClick = (e: MouseEvent) => {
|
|
31
|
+
if (e.target instanceof Node && !ref.current?.contains(e.target))
|
|
32
|
+
setOpen(false);
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
window.addEventListener('click', onClick);
|
|
36
|
+
return () => window.removeEventListener('click', onClick);
|
|
37
|
+
}, [open]);
|
|
38
|
+
|
|
39
|
+
return (
|
|
40
|
+
<Collapsible
|
|
41
|
+
open={open}
|
|
42
|
+
onOpenChange={setOpen}
|
|
43
|
+
{...container}
|
|
44
|
+
className={cn('max-md:layout:[--toc-popover-height:--spacing(10)]', container?.className)}
|
|
45
|
+
>
|
|
46
|
+
<header ref={ref} className="bg-card">
|
|
47
|
+
<CollapsibleTrigger
|
|
48
|
+
{...trigger}
|
|
49
|
+
className={cn(
|
|
50
|
+
'flex w-full h-10 items-center gap-2.5 px-4 text-start text-sm text-muted-foreground focus-visible:outline-none',
|
|
51
|
+
trigger?.className,
|
|
52
|
+
)}
|
|
53
|
+
>
|
|
54
|
+
<OutlineProgress
|
|
55
|
+
size={18}
|
|
56
|
+
className={cn('shrink-0', open && 'text-primary')}
|
|
57
|
+
/>
|
|
58
|
+
<OutlineActiveHeading
|
|
59
|
+
fallback={page?.name ?? t('ui.on_this_page')}
|
|
60
|
+
className={cn('flex-1 transition-colors', open && 'text-foreground')}
|
|
61
|
+
/>
|
|
62
|
+
<ChevronDownIcon
|
|
63
|
+
className={cn('size-4 shrink-0 mx-0.5 transition-transform', open && 'rotate-180')}
|
|
64
|
+
/>
|
|
65
|
+
</CollapsibleTrigger>
|
|
66
|
+
<CollapsibleContent {...content}>
|
|
67
|
+
<div className="flex flex-col px-4 max-h-[50vh]">
|
|
68
|
+
{header}
|
|
69
|
+
<OutlineList {...props} onSelect={() => setOpen(false)} />
|
|
70
|
+
{footer}
|
|
71
|
+
</div>
|
|
72
|
+
</CollapsibleContent>
|
|
73
|
+
</header>
|
|
74
|
+
</Collapsible>
|
|
75
|
+
);
|
|
76
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import type { ComponentProps, ReactNode } from 'react';
|
|
2
|
+
import type * as OutlineDefault from '@terrafirmagreg-team/kit/components/toc/default';
|
|
3
|
+
import type * as OutlineClerk from '@terrafirmagreg-team/kit/components/toc/clerk';
|
|
4
|
+
import type * as OutlineBlock from '@terrafirmagreg-team/kit/components/toc/block';
|
|
5
|
+
|
|
6
|
+
export type OutlineStyle =
|
|
7
|
+
| { style?: 'block'; list?: OutlineBlock.TOCItemsProps }
|
|
8
|
+
| { style: 'normal'; list?: OutlineDefault.TOCItemsProps }
|
|
9
|
+
| { style: 'clerk'; list?: OutlineClerk.TOCItemsProps };
|
|
10
|
+
|
|
11
|
+
export type OutlineContent = {
|
|
12
|
+
|
|
13
|
+
header?: ReactNode;
|
|
14
|
+
|
|
15
|
+
footer?: ReactNode;
|
|
16
|
+
} & OutlineStyle;
|
|
17
|
+
|
|
18
|
+
export type OutlineProps = OutlineContent & {
|
|
19
|
+
container?: ComponentProps<'div'>;
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
export type WorkspaceOutlineDropdownProps = OutlineContent & {
|
|
23
|
+
trigger?: ComponentProps<'button'>;
|
|
24
|
+
content?: ComponentProps<'div'>;
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
export type WorkspaceOutlinePopoverProps = WorkspaceOutlineDropdownProps & {
|
|
28
|
+
container?: ComponentProps<'div'>;
|
|
29
|
+
};
|